package com.webdev.base.controller;


import com.webdev.base.pojo.User;
import com.webdev.base.service.IUserService;
import com.webdev.base.vo.AddressVo;
import com.webdev.base.vo.RespBean;
import com.webdev.base.vo.RespBeanEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author huangningshuang
 * @since 2021-12-13
 */
@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;

    @RequestMapping("/userInfo")
    @ResponseBody
    public RespBean userInfo(User user) {
        if (user == null) {
            return RespBean.error(RespBeanEnum.SESSION_ERROR);
        }
        return RespBean.success(user);
    }

    @RequestMapping("/addressInfo")
    @ResponseBody
    public RespBean addressInfo(User user, AddressVo addr) {
        if (user == null) {
            return RespBean.error(RespBeanEnum.SESSION_ERROR);
        }
        userService.updateUserAddr(addr, user.getUserId());
        return RespBean.success();
    }
}
